binaries=kylin_verify kylin_gen_register kylin_activate kylin_activation_check kylin_serial kylin_activate_ukey kylin_ukey_dump kylin_status_check kylin_qrcode kylin_encrypted_hardware_info
libraries=libkylin-activation.so


all:$(binaries) $(libraries) po/libkylin-activation_zh_CN.mo po/kylin-system-verify_zh_CN.mo po/libkylin-activation_bo_CN.mo po/kylin-system-verify_bo_CN.mo po/libkylin-activation_mn.mo po/kylin-system-verify_mn.mo

CC_FLAGS=$(shell pkg-config --cflags glib-2.0 libcdio) -Wall -D_FILE_OFFSET_BITS=64 -DCHECK_ENV -DDEB_PACKAGE -O0
LD_FLAGS=$(shell pkg-config --libs glib-2.0 libcdio) -lgpgme -lgpg-error -pthread -lcrypt -lcrypto -lssl -lassuan -lblkid -luuid -ldl -lusb-1.0

objs=gpgverify.o keyfile.o lic-parse.o date.o dict.o encrypt.o hwid.o \
     misc.o kylin-activation.o cmdline.o ukey-common.o kylin-license.o ftkey.o vikey.o lmkey.o fykey.o digest.o \
     env-check.o base64.o transform.o ssl.o info_crypt.o escape.o
sharedobjs=gpgverify-sh.o keyfile-sh.o lic-parse-sh.o date-sh.o dict-sh.o \
           encrypt-sh.o hwid-sh.o misc-sh.o kylin-activation-sh.o digest-sh.o\
           cmdline-sh.o ukey-common-sh.o kylin-license-sh.o ftkey-sh.o vikey-sh.o lmkey-sh.o fykey-sh.o env-check-sh.o \
           base64-sh.o transform-sh.o ssl-sh.o info_crypt-sh.o escape-sh.o

kylin_verify:$(objs) kylin-verify.c
	$(CC) kylin-verify.c -DUSERSPACE_PROGRAM -o kylin_verify $(objs) $(CC_FLAGS) $(LD_FLAGS) 

kylin_gen_register:$(objs) kylin-gen-register.c
	$(CC) kylin-gen-register.c -DUSERSPACE_PROGRAM -o kylin_gen_register $(objs) $(CC_FLAGS) $(LD_FLAGS) 

kylin_encrypted_hardware_info:$(objs) kylin-encrypted-hardware-info.c
	$(CC) kylin-encrypted-hardware-info.c -DUSERSPACE_PROGRAM -o kylin_encrypted_hardware_info $(objs) $(CC_FLAGS) $(LD_FLAGS) 

kylin_activate:$(objs) kylin-activate.c
	$(CC) kylin-activate.c -o kylin_activate $(objs) $(CC_FLAGS) $(LD_FLAGS) 

kylin_activate_ukey:$(objs) kylin-activate-ukey.c
	$(CC) kylin-activate-ukey.c -o kylin_activate_ukey $(objs) $(CC_FLAGS) $(LD_FLAGS) 

kylin_activation_check:$(objs) kylin-activation-check.c
	$(CC) kylin-activation-check.c -DUSERSPACE_PROGRAM -o kylin_activation_check $(objs) $(CC_FLAGS) $(LD_FLAGS) 

kylin_status_check:$(objs) kylin-status-check.c
	$(CC) kylin-status-check.c -DUSERSPACE_PROGRAM -o kylin_status_check $(objs) $(CC_FLAGS) $(LD_FLAGS) 

kylin_qrcode:$(objs) kylin-qrcode.c
	$(CC) kylin-qrcode.c -DUSERSPACE_PROGRAM -o kylin_qrcode $(objs) $(CC_FLAGS) $(LD_FLAGS)

kylin_serial:$(objs) kylin-serial.c
	$(CC) kylin-serial.c $(objs) -o kylin_serial $(CC_FLAGS) $(LD_FLAGS) 

kylin_ukey_dump:$(objs) kylin-ukey-dump.c
	$(CC) kylin-ukey-dump.c $(objs) -o kylin_ukey_dump $(CC_FLAGS) $(LD_FLAGS) 

gpgverify.o:gpgverify.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c gpgverify.c

keyfile.o:keyfile.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c keyfile.c

lic-parse.o:lic-parse.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c lic-parse.c

date.o:date.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c date.c

dict.o:dict.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c dict.c

encrypt.o:encrypt.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c encrypt.c

hwid.o:hwid.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c hwid.c


misc.o:misc.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c misc.c

cmdline.o:cmdline.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c cmdline.c
	
ukey-common.o:ukey-common.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c ukey-common.c

kylin-license.o:kylin-license.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c kylin-license.c

ftkey.o:ftkey.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c ftkey.c

vikey.o:vikey.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c vikey.c

lmkey.o:lmkey.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c lmkey.c

fykey.o:fykey.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c fykey.c

env-check.o:env-check.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c env-check.c

digest.o:digest.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c digest.c

base64.o:base64.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c base64.c

ssl.o:ssl.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c ssl.c

transform.o:transform.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c transform.c

info_crypt.o:info_crypt.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c info_crypt.c

escape.o:escape.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c escape.c

kylin-activation.o:kylin-activation.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c kylin-activation.c

libkylin-activation.so:$(sharedobjs)
	$(CC)  $(sharedobjs) $(LD_FLAGS) -o libkylin-activation.so -shared


gpgverify-sh.o:gpgverify.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c gpgverify.c -o gpgverify-sh.o -fPIC

keyfile-sh.o:keyfile.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c keyfile.c -o keyfile-sh.o -fPIC

lic-parse-sh.o:lic-parse.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c lic-parse.c -o lic-parse-sh.o -fPIC

date-sh.o:date.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c date.c -o date-sh.o -fPIC

dict-sh.o:dict.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c dict.c -o dict-sh.o -fPIC

encrypt-sh.o:encrypt.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c encrypt.c -oencrypt-sh.o -fPIC

hwid-sh.o:hwid.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c hwid.c -o hwid-sh.o -fPIC

misc-sh.o:misc.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c misc.c -o misc-sh.o -fPIC

cmdline-sh.o:cmdline.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c cmdline.c -o cmdline-sh.o -fPIC

ukey-common-sh.o:ukey-common.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c ukey-common.c -o ukey-common-sh.o -fPIC

kylin-license-sh.o:kylin-license.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c kylin-license.c -o kylin-license-sh.o -fPIC

ftkey-sh.o:ftkey.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c ftkey.c -o ftkey-sh.o -fPIC

lmkey-sh.o:lmkey.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c lmkey.c -o lmkey-sh.o -fPIC

fykey-sh.o:fykey.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c fykey.c -o fykey-sh.o -fPIC

vikey-sh.o:vikey.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c vikey.c -o vikey-sh.o -fPIC

env-check-sh.o:env-check.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c env-check.c -o env-check-sh.o -fPIC

digest-sh.o:digest.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c digest.c -o digest-sh.o -fPIC

base64-sh.o:base64.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c base64.c -o base64-sh.o -fPIC

ssl-sh.o:ssl.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c ssl.c -o ssl-sh.o -fPIC

transform-sh.o:transform.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c transform.c -o transform-sh.o -fPIC

info_crypt-sh.o:info_crypt.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c info_crypt.c -o info_crypt-sh.o -fPIC

escape-sh.o:escape.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c escape.c -o escape-sh.o -fPIC

kylin-activation-sh.o:kylin-activation.c
	$(CC) $(CC_FLAGS) $(LD_FLAGS) -c kylin-activation.c -o kylin-activation-sh.o -fPIC

po/libkylin-activation_zh_CN.mo:po/libkylin-activation_zh_CN.po
	msgfmt po/libkylin-activation_zh_CN.po -o po/libkylin-activation_zh_CN.mo

po/libkylin-activation_bo_CN.mo:po/libkylin-activation_bo_CN.po
	msgfmt po/libkylin-activation_bo_CN.po -o po/libkylin-activation_bo_CN.mo

po/libkylin-activation_mn.mo:po/libkylin-activation_mn.po
	msgfmt po/libkylin-activation_mn.po -o po/libkylin-activation_mn.mo

po/kylin-system-verify_zh_CN.mo:po/kylin-system-verify_zh_CN.po
	msgfmt po/kylin-system-verify_zh_CN.po -o po/kylin-system-verify_zh_CN.mo

po/kylin-system-verify_bo_CN.mo:po/kylin-system-verify_bo_CN.po
	msgfmt po/kylin-system-verify_bo_CN.po -o po/kylin-system-verify_bo_CN.mo

po/kylin-system-verify_mn.mo:po/kylin-system-verify_mn.po
	msgfmt po/kylin-system-verify_mn.po -o po/kylin-system-verify_mn.mo

clean:
	rm -f $(binaries)
	rm -f $(libraries)
	rm -f *.o
	rm -f po/*.mo


install:all
	mkdir -p $(DESTDIR)/usr/bin
	install -m 755 kylin_verify $(DESTDIR)/usr/bin
	install -m 755 kylin_gen_register $(DESTDIR)/usr/bin
	install -m 755 kylin_activate $(DESTDIR)/usr/bin
	install -m 755 kylin_activate_ukey $(DESTDIR)/usr/bin
	install -m 755 kylin_activation_check $(DESTDIR)/usr/bin
	install -m 755 kylin_status_check $(DESTDIR)/usr/bin
	install -m 755 kylin_serial $(DESTDIR)/usr/bin
	install -m 755 kylin_qrcode $(DESTDIR)/usr/bin
	install -m 755 kylin_ukey_dump $(DESTDIR)/usr/bin
	install -m 755 kylin-system-verify $(DESTDIR)/usr/bin
	install -m 755 kylin-system-verify-legacy $(DESTDIR)/usr/bin
	install -m 755 kylin-system-verify-new $(DESTDIR)/usr/bin
	mkdir -p $(DESTDIR)/usr/lib/
	install -m 644 libkylin-activation.so $(DESTDIR)/usr/lib/
	mkdir -p $(DESTDIR)/usr/include
	install -m 644 kylin-activation.h $(DESTDIR)/usr/include
	mkdir -p $(DESTDIR)/usr/share/locale/zh_CN/LC_MESSAGES
	install -m 644 po/libkylin-activation_zh_CN.mo $(DESTDIR)/usr/share/locale/zh_CN/LC_MESSAGES/libkylin-activation.mo
	install -m 644 po/kylin-system-verify_zh_CN.mo $(DESTDIR)/usr/share/locale/zh_CN/LC_MESSAGES/kylin-system-verify.mo
	mkdir -p $(DESTDIR)/usr/share/locale/bo_CN/LC_MESSAGES
	install -m 644 po/libkylin-activation_bo_CN.mo $(DESTDIR)/usr/share/locale/bo_CN/LC_MESSAGES/libkylin-activation.mo
	install -m 644 po/kylin-system-verify_bo_CN.mo $(DESTDIR)/usr/share/locale/bo_CN/LC_MESSAGES/kylin-system-verify.mo
	mkdir -p $(DESTDIR)/usr/share/locale/mn/LC_MESSAGES
	install -m 644 po/libkylin-activation_mn.mo $(DESTDIR)/usr/share/locale/mn/LC_MESSAGES/libkylin-activation.mo
	install -m 644 po/kylin-system-verify_mn.mo $(DESTDIR)/usr/share/locale/mn/LC_MESSAGES/kylin-system-verify.mo

uninstall:
	rm -f /usr/bin/kylin_verify
	rm -f /usr/bin/kylin_serial
	rm -f /usr/bin/kylin_gen_register
	rm -f /usr/bin/kylin_activate
	rm -f /usr/bin/kylin_activate_ukey
	rm -f /usr/bin/kylin_activation_check
	rm -f /usr/bin/kylin_status_check
	rm -f /usr/bin/kylin_serial
	rm -f /usr/bin/kylin_qrcode
	rm -f /usr/bin/kylin_ukey_dump
	rm -f /usr/bin/kylin-system-verify
	rm -f /usr/bin/kylin-system-verify-legacy
	rm -f /usr/bin/kylin-system-verify-new
	rm -f /usr/include/kylin-activation.h
	rm -f /usr/lib/libkylin-activation.so
	rm -f /usr/share/locale/zh_CN/LC_MESSAGES/libkylin-activation.mo
	rm -f /usr/share/locale/zh_CN/LC_MESSAGES/kylin-system-verify.mo
	rm -f /usr/share/locale/bo_CN/LC_MESSAGES/libkylin-activation.mo
	rm -f /usr/share/locale/bo_CN/LC_MESSAGES/kylin-system-verify.mo


